home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / hypercrd / xcmds / dvlprstc.hqx / Developer Stack 1.3r / card_44247.txt < prev    next >
Text File  |  1991-04-30  |  10KB  |  232 lines

  1. -- card: 44247 from stack: in.3r
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 13187
  5. -- name: ChangeObjectLayer
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. 7
  11.  
  12. -- part contents for background part 18
  13. ----- text -----
  14. Scripts
  15.  
  16. -- part contents for background part 2
  17. ----- text -----
  18. ChangeObjectLayer
  19.  
  20. -- part contents for background part 3
  21. ----- text -----
  22. About "ChangeObjectLayer" 1.0...
  23.  
  24. ΓÇóYou've heard of ShareWare and FreeWare!  I now introduce TradeWare!!!
  25.  
  26. This script is TradeWare.  If you find it useful, send me an 800K floppy packed with ShareWare and FreeWare goodies; I am especially interested in HyperCard development tools and utilities (such as XCMD/XFCNs, etc.ΓÇöI already have the Developer Stack, Thank You), and system tools and utilities (INITs and CDEVs, etc).  In return, I will send your disk back to you with ShareWare and FreeWare goodies from my own collection.  No sound stacks, pleaseΓÇöthey're too obnoxious, and wasteful of disk space and memory.
  27.  
  28. Please send neat (and/or useful) stuff to:
  29. Dean H. Wette
  30. 921 DeMun Avenue 2N
  31. Clayton, MO  63105
  32. 314-863-4944                                                       
  33.  
  34. ΓÇóNow...finally...about ChangeObjectLayer...
  35.  
  36. While developing a stack containing numerous modal popup dialogs, fields, and buttons, I found myself constantly going to the "Objects" menu for the "Send Farther" and "Bring Closer" commands in order to move objects (buttons and fields) through different card and background layers.  In some cases I wanted to obscure other objects, and in other cases I wanted to prevent objects from being obscured.  Well, anyway, when you have 20 or more each of background and card buttons and fields, this menu selection (or its command key equivalent) business to change object layers can become quite tedious and boring.  
  37.  
  38. Therefore, I developed "ChangeObjectLayer" to automate  and speed-up the process of moving objects' through different layers.  "ChangeObjectLayer" works with both card and background buttons and fields.  Try it out!  On this card are six each of card and background buttons and fields.  See the effect of changing a card/background  button/field from 6 to 1 and vice versa.
  39.  
  40. ΓÇóTo install ChangeObjectLayer functions
  41. 1) Copy the handler "setLayer" and the function "theLayer" plus the two utility handlers "setLocksTrue" and "setLocksFalse."
  42. 2) Paste everything into a card, background, or stack script.  The best place for the "ChangeObjectLayer" scripts and the "setLocks" scripts is in the stack script of your Home stack, thus making the script available in all stacks.
  43.  
  44. ΓÇóTo invoke "ChangeObjectLayer" do the following:
  45. 1) Open the script editing window of the object (button or field) you want to change.
  46. 2a) If the object contains a script then add "setLayer" (with-out the quotes) as the second line of the objects scriptΓÇöthe line following "on mouseUp."   The part of the script following "setLayer" will be disabled until you remove the call to "setLayer."  
  47. 2b) If the object does not already have a script then type the following script in the script editing window:
  48.  
  49. on mouseUp
  50.     setLayer
  51. end mouseUp
  52.  
  53. 3) Click "OK" to close the editing window and then click on the object (make sure the browse tool is selected).  Note: if the object is a field, then the lockText property must be set to true (i.e. lock the field) for "ChangeObjectLayer" to work.
  54. 4) You will be prompted to specify the number to which the object will be set.  The prompt will indicate the valid range (e.g. "1-6" - you can't set a card button to 'card button 7' if there are only 6 card buttons).  Enter a valid number, click "OK", and wait.  "ChangeObjectLayer" will beep three times when it finished with its task.
  55. 5) Remove the "setLayer" line from the object script to reenable any original object script.  If the "setLayer" call is the second line of the object's script, it will be removed for you.
  56.  
  57. [Hey Bill, can we fix the orphan quotes and parentheses?!?!]
  58.  
  59. ΓÇóNotes:
  60. The "setLayer" handler concludes with an "exit to HyperCard" command so if you call it from an existing handler in a button or field, any script folowing the call will not execute until you remove the "setLayer" line of your object script.
  61.  
  62. Sometimes, when an object is set to its highest or lowest number it may still obscureΓÇöor be obscuredΓÇöby an object of its unlike type (field/button or vice versa).  To remedy this, you may need to invoke "Send Farther" or "Bring Closer" additional times (i.e. use "Bring Closer" when an object is at its highest number already, or "Send Farther" when it is at its lowest number).  This can be accomplished with "ChangeObjectLayer".  [Those damn orphan quotes again!]  If you hold down the optionkey while invoking the "setLayer" handler from an object, you can enter an invalid object number (such as 0 or 1,000,000).  This will cause "ChangeObjectLayer" to invoke the "Send Farther" or "Bring Closer" menu commands forever.  Press Command-. (period) to stop the repeated execution, and press Command-Tab to select the browse tool.  The "setLayer" handler can be invoked once again in similar manner if necessary.
  63.  
  64. ΓÇóWell, that's about it for "ChangeObjectLayer" 1.0.  I wrote and tested it on Friday, July, 29, 1988.  If you find any bugs or have suggestions for improvements please let me know (no collect calls please).  Happy setLayering!
  65.  
  66.  
  67. --ChangeObjectLayer 1.0
  68. --┬⌐1988 by Dean H Wette
  69. --921 DeMun Avenue 2N
  70. --Clayton, MO  63105
  71. --314-863-4944
  72. --Please include the above credits with the script.
  73. --This script is TradeWare. See above
  74. --for more information and instructions.
  75.  
  76. ------------------------------------------------------------------------
  77.  
  78. --The best place for these scripts is in the Home stack, thus
  79. --making "ChangeObjectLayer" available to all your stacks.
  80.  
  81. --Begin ChangeObjectLayer 1.0
  82.  
  83. --This is the handler called by the target object.
  84. --The call, "setLayer", should be the second line
  85. --of the object's script, after "on mouseUp".
  86.  
  87. on setLayer
  88.   global objectNumber,objectType,optionState
  89.   put the optionKey into optionState
  90.   
  91.   --We need information about the target object ΓÇö get it from
  92.   --the "objectInfo" function.
  93.   put objectInfo() into doMenuWhich
  94.   
  95.   setLocksTrue  -- Don't forget to include the "setLocks" handlers!
  96.   
  97.   --Go from the browse tool to the object's editing tool
  98.   --and select the object.
  99.   if objectType = "button" then choose btn tool else choose fld tool
  100.   select the target
  101.   
  102.   --This is where the work gets done.
  103.   
  104.   repeat until the number of the target = objectNumber
  105.     set cursor to busy
  106.     
  107.     --Find out if the object goes to a higher or lower layer, or
  108.     --if it's all just a waste of time.
  109.     if doMenuWhich < 0 then doMenu "Send Farther"
  110.     if doMenuWhich > 0 then doMenu "Bring Closer"
  111.     if doMenuWhich = 0 then exit repeat
  112.   end repeat
  113.   beep 3
  114.   
  115.   --We're finished so let's clean up & return everything to normal.
  116.   set cursor to 4
  117.   choose browse tool
  118.   setLocksFalse
  119.   put empty into objectNumber
  120.   put empty into objectType
  121.   put empty into optionState
  122.   
  123.   --Let's remove the "setLayer" call for the user, that is,
  124.   --if it's in the right place!
  125.   if line 2 of script of target contains "setLayer" then
  126.     put script of target into objectScript
  127.     put empty into line 2 of objectScript
  128.     set script of target to objectScript
  129.   else
  130.   end if
  131.   
  132.   --We just want to change the object's layer so let's not
  133.   --execute its normal script
  134.   exit to HyperCard
  135.   
  136. end setLayer
  137.  
  138. --This is the function that returns all the object information
  139. --needed to allow "setLayer" to perform properly.
  140.  
  141. function objectInfo
  142.   global objectNumber,objectType,optionState
  143.   
  144.   --Is the Object a field or a button?
  145.   if the name of the target contains "field" then
  146.     put "field" into objectType
  147.   else
  148.     put "button" into objectType
  149.   end if
  150.   
  151.   --Is the object a card or background object?
  152.   if the name of the target contains "bkgnd" then
  153.     put "bkgnd" into objectClass
  154.   else
  155.     put "card" into objectClass
  156.   end if
  157.   
  158.   --What is the object's current number?
  159.   put the number of the target into fromThis
  160.   
  161.   --What is the highest possible number of the object
  162.   if objectType = "button" then
  163.     if the name of the target contains "bkgnd" then
  164.       put the number of last bg btn into theRange
  165.     else
  166.       put the number of last btn into theRange
  167.     end if
  168.   else
  169.     if objectType = "field" then
  170.       if the name of the target contains "card" then
  171.         put the number of last cd field into theRange
  172.       else
  173.         put the number of last field into theRange
  174.       end if
  175.     end if
  176.   end if
  177.   --Now we know the object's possible range.
  178.   
  179.   --This is the function part of the function.  It returns
  180.   --the target number of the object.
  181.   
  182.   --Prompt the user for a target object number
  183.   --& give the valid range of numbers.
  184.   ask "Set " &objectClass &&objectType &&fromThis && ┬¼
  185.   "to what number? (1-" &theRange &")"
  186.   if it is empty then exit to HyperCard
  187.   set cursor to 4
  188.   put it into objectNumber
  189.   
  190.   --If user holds down option key while invoking "setLayer"
  191.   --then the following error checking is bypassed.
  192.   if optionState is up then
  193.     
  194.     --Error checking...make sure the user enters a valid number.
  195.     if objectNumber > theRange or objectNumber < 1 then
  196.       beep
  197.       answer "Sorry!  ΓÇ£" &objectNumber &"ΓÇ¥ is not a valid "┬¼
  198.       &objectType &&"number."
  199.       exit to HyperCard
  200.     else
  201.     end if
  202.   end if
  203.   
  204.   --Now we have the target number and information we need to proceed.
  205.   return objectNumber - fromThis
  206. end objectInfo
  207.  
  208. --end ChangeObjectLayer 1.0
  209.  
  210. ------------------------------------------------------------------------
  211.  
  212. --These two utility handlers are called by "ChangeObjectLayer,"
  213. --so make sure you include them.  I did not write these handlers,
  214. --and I can't remember where I got them.  My apologies to whoever
  215. --deserves due credit for "setLocks".
  216.  
  217. --This one locks everything!
  218. on setLocksTrue
  219.   lock screen
  220.   set lockRecent to true
  221.   set lockMessages to true
  222. end setLocksTrue
  223.  
  224. --This one unlocks everything!
  225. on setLocksFalse
  226.   unlock screen
  227.   set lockRecent to false
  228.   set lockMessages to false
  229. end setLocksFalse
  230.  
  231. --YOU NEED ALL THE ABOVE SCRIPTS FOR "CHANGEOBJECTLAYER" TO WORK!!!
  232.